package graficos;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;

public class CriaGrafico {

    private TimeSeries timeSerie;
    private TimeSeriesCollection dataset;

    public CriaGrafico(String tipo) {
        timeSerie = new TimeSeries(tipo, Millisecond.class);
        dataset = new TimeSeriesCollection();
    }

    public ChartPanel getGrafico() {

        JFreeChart chart = ChartFactory.createTimeSeriesChart("Variação de Temperatura", // titulo do grafico
                "Tempo", // eixo X
                "Temperatura ( ̊C)", // eixo Y
                this.atualizarDataset(), // dados para o grafico
                true,
                true,
                false);


        ChartPanel chartPanel = new ChartPanel(chart, false);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        chartPanel.setMouseZoomable(true, false);

        return chartPanel;
    }

    public XYDataset atualizarDataset() {

        dataset.addSeries(timeSerie);
        dataset.setDomainIsPointsInTime(true);
        return dataset;

    }


    public TimeSeries getTimeSerie() {
        return timeSerie;
    }

    public void setTimeSerie(TimeSeries s1) {
        this.timeSerie = s1;
    }

}
